package com.szsh.aiot.hsm.controller;

import com.google.gson.JsonObject;
import com.szsh.aiot.common.annotation.CustomPermission;
import com.szsh.aiot.common.annotation.Log;
import com.szsh.aiot.common.core.domain.AjaxResult;
import com.szsh.aiot.common.core.domain.RequestDto;
import com.szsh.aiot.common.enums.BusinessType;
import com.szsh.aiot.hsm.dto.enu.NumberEnum;
import com.szsh.aiot.hsm.service.HousekeepingService;
import com.szsh.aiot.hsm.service.LoginService;
import com.szsh.aiot.hsm.utils.PermitValidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:天翼账号登录管理
 * @Date 2023/10/24: 9:50
 * @Author: LOADING>>>>>
 */
@Controller
@RequestMapping("/houseKeeper")
public class HouseKeeperController {

    @Autowired
    private LoginService loginService;

    @Autowired
    private HousekeepingService housekeepingService;

    @Autowired
    private PermitValidUtil permitValidUtil;


    /**
     * 6.1.1 通过此接口获取天翼账号登录信息
     *
     * @param requestDto 请求参数
     * @return 处理结果
     */
    @RequestMapping(value = "/getUserLoginInfos")
    @Log(title = "获取天翼账号登录信息", businessType = BusinessType.OTHER)
    @CustomPermission(isValidateTyAccount = false)
    @ResponseBody
    public AjaxResult userLoginInfo(@RequestBody RequestDto requestDto) throws Exception {
        String sequenceNo = requestDto.getSequenceNo();
        JsonObject requestParams = requestDto.getRequestJsonElement().getAsJsonObject();
        String phone = permitValidUtil.getElementValue(requestParams, "phone");
        return loginService.getUserLoginInfos(phone);
    }


    /**
     * 6.2.1 通过此接口获取天翼看家摄像头设备及相关记录数据信息
     *
     * @param requestDto 请求参数
     * @return 处理结果
     */
    @RequestMapping(value = "/camera/deviceInfo")
    @Log(title = "获取天翼看家摄像头设备及相关记录数据信息", businessType = BusinessType.OTHER)
    @CustomPermission(isValidateTyAccount = false)
    @ResponseBody
    public AjaxResult cameraDeviceInfo(@RequestBody RequestDto requestDto) throws Exception {
        String sequenceNo = requestDto.getSequenceNo();
        JsonObject requestParams = requestDto.getRequestJsonElement().getAsJsonObject();
        String operaType = permitValidUtil.getElementValue(requestParams, "operaType");

        switch (operaType) {
            //看家卫士页面-获取3天内摄像头访问提醒数据
            case NumberEnum.STR_1:
                String broadbandNO = permitValidUtil.getElementValue(requestParams, "broadbandNO");
                return housekeepingService.getEhomeCameraAccessInfos(broadbandNO);
            //看家卫士页面-删除绑定的天翼看家摄像头设备
            case NumberEnum.STR_2:
                Long deviceID = Long.valueOf(permitValidUtil.getElementValue(requestParams, "id"));
                return housekeepingService.deleteEhomeCameraInfo(deviceID);

            //看家卫士页面-绑定天翼看家摄像头的手机号
            case NumberEnum.STR_3:
                broadbandNO = permitValidUtil.getElementValue(requestParams, "broadbandNO");
                String phone = permitValidUtil.getElementValue(requestParams, "phone");
                return housekeepingService.bindEhomePhone(broadbandNO, phone);

            //获取天翼摄像头访问记录数据
            case NumberEnum.STR_4:
                broadbandNO = permitValidUtil.getElementValue(requestParams, "broadbandNO");
                int pageno = Integer.parseInt(permitValidUtil.getElementValue(requestParams, "pageno"));
                String devicecode = permitValidUtil.getElementValue(requestParams, "devicecode");
                return housekeepingService.getCameraAccessInfos(devicecode, pageno, broadbandNO);
            default:
                AjaxResult.badRequest("未知操作，请确认后重新操作");
                break;
        }
        return AjaxResult.badRequest("未知操作，请确认后重新操作");

    }
}
